//const baseUrl = "https://m.zhiliaoyuedu.cn/app/consumer";
const baseUrl = "http://localhost:8080";

function request(params) {
  wx.request({
    url: baseUrl + params.url,
    method:"POST",
    data: params.data,
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: res => {
      if (res.data.code == 0) {
        if (res.data.result != null){
          params.success(res.data.result)
        }else{
          params.success(res.data)
        }
      } else {
        showError(res.data.desc)
      }
    },
    fail: error => {
      showError()
    }
  })
}

function showError(error) {
  if(error){
    wx.showToast({
      title: error,
      icon: "none"
    })
  }else{
    wx.showToast({
      title: "请求错误",
      icon: "none"
    })
  }
}



module.exports = request